﻿using Hopscotch.Domain.Common;
using Hopscotch.Domain.Common.StateTracking;
using Hopscotch.EntityModel.Finance;
using System.Linq;


namespace Hopscotch.Server.AppService
{
    /// <summary>
    ///
    /// </summary>
    /// <remarks>This class exists because .net does not allow generic constracts on value types</remarks>
    public class DomainServiceIntKey<T> : DomainService<T, int>
        where T : DomainBase<int>, IObjectWithChangeTracker, new()
    {
        public override T Get(int id)
        {
            using (var context = new FinDbModelContext())
            {
                var q = from t in context.CreateDomainCollection<T>()
                        where t.Id == id
                        select t;

                T domainObject = q.FirstOrDefault();
                return domainObject;
            }

        }
    }
}
